//
//  ViewController.m
//  02-UIViewController
//
//  Created by mafeng on 16/7/15.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#import "PresentViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *subView;
@end

@implementation ViewController
// 初始化方法
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // 不要在这个方法中加载视图  (因为: 用self.view的话会调用loadView方法, 然后下面的就不执行了*.*)        //
        // 在这个方法中去初始化一些数据方面的东西
    }
    return self;
}
// loadView 加载UIViewController中的view
// UINavigationController
// UITableViewControlller 在loadView中重新赋值了
- (void)loadView {
    [super loadView];
    NSLog(@"load view");
    // 改变self.view
}
// view 已经加载
// 所有自定义视图的创建
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"view did load");
    // 执行下面的代码会进入死循环, 然后爆炸, 因为view的属性是懒加载
  /*  self.view = nil;
    NSLog(@"%@", self.view);
   */
    
    // 模态
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    PresentViewController *present = [[PresentViewController alloc] init];
    // 模态, 动画效果
    // UIModalTransitionStyleCoverVertical 默认效果, 从下往上
    // UIModalTransitionStyleFlipHorizontal 左右旋转翻页
    // UIModalTransitionStyleCrossDissolve 渐变效果
    //  UIModalTransitionStylePartialCurl 翻书效果
    present.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    // 模态, 一个视图控制器
    [self presentViewController:present animated:YES completion:^{
        
        
    }];
    
}
// 注意: init loadview viewdidload 只执行一次

// 下面的方法会执行多次
// 视图将要出现时
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
// 视图已经出现
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
// 视图将要消失时
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}
// 视图已经消失
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
- (UIView *)subView {
    if (_subView == nil) {
        _subView = [UIView new];
    }
    return _subView;
}
// 接收到内存警告时, 执行的方法
- (void)didReceiveMemoryWarning {
    // 从父类继承的方法中有内存警告的打印
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    // 释放内存资源
    // 把未显示在屏幕上的资源置空
}

@end
